// 定义环境配置类型
interface EnvironmentConfig {
  apiBaseUrl: string;
}

// 环境配置
const environments: Record<'development' | 'production', EnvironmentConfig> = {
  development: {
    apiBaseUrl: 'http://127.0.0.1:8089/api/v1'
  },
  production: {
    apiBaseUrl: 'http://ie.ynd777.com/api/v1'
  }
};

// 获取当前环境
let env: 'development' | 'production' = 'development';

try {
  // 尝试获取 Electron app 对象
  const { app } = require('electron');
  if (app && app.isPackaged) {
    env = 'production';
    console.log('[Config] Detected packaged app, using production config');
  } else {
    env = (process.env.NODE_ENV as 'development' | 'production') || 'development';
    console.log('[Config] Using NODE_ENV:', process.env.NODE_ENV);
  }
} catch (error) {
  // 如果无法获取 app 对象（比如在渲染进程中），使用 NODE_ENV
  env = (process.env.NODE_ENV as 'development' | 'production') || 'development';
  console.log('[Config] Fallback to NODE_ENV:', process.env.NODE_ENV);
}

// 导出对应环境的配置
export const apiBaseUrl: string = environments[env].apiBaseUrl;

console.log(`[Config] Environment: ${env}, API Base URL: ${apiBaseUrl}`);